﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Unitity;
using Microsoft.Xna.Framework;
using Spinning.Spinning.EntityModifiers;
using Spinning.Spinning.Level;
using Microsoft.Xna.Framework.Input.Touch;

namespace Spinning.Spinning.Entity.Scenes
{
    class MenuScene : Scene
    {
        public override void OnLoad()
        {
            base.OnLoad();
            Sprite backGroundSprite = new Sprite();
            backGroundSprite.textureName = "bg";
            backGroundSprite.ZIndex = Constants.background;
            backGroundSprite.OnLoad();
            this.Attach(backGroundSprite);

            ButtonSprite backSprite = new ButtonSprite();
            backSprite.textureName = "p2/back";
            backSprite.ZIndex = Constants.ui;
            backSprite.Position = new Vector2(340, 680);
            backSprite.OnLoad();
            TouchManager.RegisteTouchArea(backSprite);
            this.Attach(backSprite);

            ButtonSprite waterSprite = new ButtonSprite();
            waterSprite.textureName = "p2/water";
            waterSprite.ZIndex = Constants.ui;
            waterSprite.Position = new Vector2(240-57, 250);
            waterSprite.OnLoad();
            TouchManager.RegisteTouchArea(waterSprite);
            this.Attach(waterSprite);

            ButtonSprite fireSprite = new ButtonSprite();
            fireSprite.textureName = "p2/fire";
            fireSprite.ZIndex = Constants.ui;
            fireSprite.Position = new Vector2(120-65, 500);
            fireSprite.OnLoad();
            TouchManager.RegisteTouchArea(fireSprite);
            this.Attach(fireSprite);

            ButtonSprite windSprite = new ButtonSprite();
            windSprite.textureName = "p2/wind";
            windSprite.ZIndex = Constants.ui;
            windSprite.Position = new Vector2(360-59, 500);
            windSprite.OnLoad();
            TouchManager.RegisteTouchArea(windSprite);
            this.Attach(windSprite);

            Sprite titleSprite = new Sprite();
            titleSprite.textureName = "p2/title_control";
            titleSprite.ZIndex = Constants.ui;
            titleSprite.Position = new Vector2(240-202, 55);
            titleSprite.OnLoad();
            this.Attach(titleSprite);

            Sprite triangleSprite = new Sprite();
            triangleSprite.textureName = "p2/triangle";
            triangleSprite.ZIndex = Constants.ui;
            triangleSprite.Position = new Vector2(240 - 87, 350);
            triangleSprite.OnLoad();
            this.Attach(triangleSprite);

            backSprite.OnTouchEvent += OnBackTouch;
            waterSprite.OnTouchEvent += OnWaterTouch;
            fireSprite.OnTouchEvent += OnFireTouch;
            windSprite.OnTouchEvent += OnWindTouch;
        }

        void OnBackTouch(BaseEntity entity, TouchLocation touchLocation)
        {
            Game1.stageManager.GoToScene("start");
        }

        void OnWaterTouch(BaseEntity entity, TouchLocation touchLocation)
        {
            Game1.stageManager.GoToScene("teachWater");
        }

        void OnFireTouch(BaseEntity entity, TouchLocation touchLocation)
        {

            Game1.stageManager.GoToScene("teachFire");
        }

        void OnWindTouch(BaseEntity entity, TouchLocation touchLocation)
        {
            Game1.stageManager.GoToScene("teachWind");
        }

        public override Scene Clone()
        {
            Scene scene = new MenuScene();
            scene.Size = new Vector2(Constants.Window_Width, Constants.Window_Height);
            scene.OnLoad();
            scene.SortChildren();
            return scene;
        }
    }
}
